#pragma once
#include "noncopyable.h"
#include <pthread.h>
#include <exception>

class Mutex:public noncopyalbe::NonCopyAble{
public:
    Mutex(){
        pthread_mutex_init(&m_mutex, NULL);
    }
    ~Mutex(){
        pthread_mutex_destroy(&m_mutex);
    }
    void Lock(){
        pthread_mutex_lock(&m_mutex);
    }
    void Unlock(){
        pthread_mutex_unlock(&m_mutex);
    }

private:
    friend class Condition;
    pthread_mutex_t m_mutex;
};

class MutexGuard: public noncopyalbe::NonCopyAble{
public:
    explicit MutexGuard(Mutex& mutex):m_mutex(mutex){
        m_mutex.Lock();
    }
    ~MutexGuard(){
        m_mutex.Unlock();
    }
private:
    Mutex& m_mutex;
};

